﻿
@{
    Layout = null;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
    <link rel="stylesheet" href="~/Content/bootstrap.min.css">
    <link rel="stylesheet" href="~/Content/style.css">
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        video {
            position: fixed;
            right: 0px;
            bottom: 0px;
            min-width: 100%;
            min-height: 100%;
            height: auto;
            width: auto;
            z-index: -11
        }

        source {
            min-width: 100%;
            min-height: 100%;
            height: auto;
            width: auto;
        }
    </style>
</head>

<body>
    <video id="v1" autoplay loop muted style="width: 100%;">
        <source src="~/Content/2.mp4" type="video/mp4" />
    </video>

    <h1>注册 微说说</h1>
    <div class="avtar">
        <img src="~/Content/avtar.png" />
    </div>
    <div class="login-form">
        <p>已有用户?<a href="login">快来登录吧！</a></p>
        <div class="alert alert-danger alert-dismissible fade show invisible text-center" style="width: 15rem;text-align: center;margin: auto;margin-top: 0px;"
             role="alert">
            <strong>提示：</strong><label for="" id="msg">555</label>
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <form id="registerForm" action="registerDone" method="POST">
            <div class="form-text">
                <input type="text" class="text" name="username" id="username" placeholder="请输入用户名">
                <input type="password" name="password" id="password" placeholder="请输入密码">
                <input type="password" name="confirmpassword" id="confirmpassword" placeholder="请确认密码">
            </div>
            <div>
                <input type="button" value="注册" onclick="jump()">
            </div>
        </form>
    </div>
    <script src="~/Scripts/jquery-3.6.0.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        var video = document.getElementById('v1');
        video.playbackRate = 1;
        function jump() {
            let username = $('#username').val();
            let password = $('#password').val();
            let confirmpassword = $('#confirmpassword').val();
            if (username.length > 0 && password.length > 0 && password === confirmpassword) {
                // ajax请求
                $.ajax({
                    url: '@Url.Action("registerDone")',
                    type: "POST",
                    data: $('#registerForm').serialize(),
                    dataType: "json",
                    success: function (res) {
                        console.log(res);
                        if (res.code === 200) {
                            window.location.href = "/users/login";
                        } else {
                            alert_fn(res.msg);
                        }

                    },
                    error: function (msg) {
                        alert_fn('网络或者服务器有问题');
                    }
               })
            } else {// 验证不通过，提示相关信息，并且阻止提交
                alert_fn();
                return false;
            }
        }

        // 这个方法包装了alert的相关行为和显示的内容
        function alert_fn(msg) {
            msg = msg || '密码不能为空，两次密码应该一致';
            // 替换提示的内容
            $('#msg').text(msg);
            // 移除不显示的class，则alert将显示
            $('.invisible').removeClass('invisible');
            // 三秒中后，给alert增加不显示的class，则alert重新隐藏
            setTimeout(() => {
                $('.alert').addClass('invisible');
            }, 3000);
        }
    </script>
</body>

</html>